using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class UVContent : MonoBehaviour
{
    private RectTransform recttf;
    public int max = 10;

    private void Awake()
    {
        recttf = GetComponent<RectTransform>();
    }

    public void ScaleAdd()
    {
        if (transform.localScale.x >= max)
        {
            transform.localScale = Vector3.one * max;
        }
        else
        {
            transform.localScale += Vector3.one;
        }
    }

    public void ScaleSub()
    {
        if (transform.localScale.x <= 1)
        {
            transform.localScale = Vector3.one;
        }
        else
        {
            transform.localScale -= Vector3.one;
        }
    }


    public void ScaleChildAdd()
    {
        foreach (Transform child in transform)
        {
            if (child.localScale.x >= 1)
            {
                child.localScale = Vector3.one;
            }
            else
            {
                child.localScale += Vector3.one * 0.1f;
            }

            child.SendMessage("DragEnds");
        }
    }

    public void ScaleChildSub()
    {
        foreach (Transform child in transform)
        {
            if (child.localScale.x <= 0.1)
            {
                child.localScale = Vector3.one * 0.1f;
            }
            else
            {
                child.localScale -= Vector3.one * 0.1f;
            }

            child.SendMessage("DragEnds");
        }
    }

    public void Save()
    {
        List<UVInfo> ls = new List<UVInfo>();
        foreach (Transform child in transform)
        {
            var info = child.GetComponent<PolygonUIMesh>().uvInfos;
            ls.AddRange(info);
        }
        
        GameObject.FindObjectOfType<DrawUV2>().Save(ls);
    }
}